package cn.bs.busuo.mall.dao.persist.repository.impl;

import cn.bs.busuo.common.pojo.vo.PageData;
import cn.bs.busuo.common.util.PageInfoToPageDataConverter;
import cn.bs.busuo.mall.dao.persist.mapper.GoodsMapper;
import cn.bs.busuo.mall.dao.persist.repository.IGoodsRepository;
import cn.bs.busuo.mall.pojo.entity.Goods;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import java.util.List;
@Slf4j
@Repository
public class GoodsRepositoryImpl implements IGoodsRepository {
    @Autowired
    private GoodsMapper goodsMapper;

    @Override
    public int updateById(Goods goods) {
        return goodsMapper.updateById(goods);
    }

    @Override
    public Goods getStandardById(Long id) {
        return goodsMapper.getStandardById(id);
    }

    @Override
    public PageData<Goods> listByRecommend(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Goods> list = goodsMapper.listByRecommend();
        PageInfo<Goods> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }

    @Override
    public PageData<Goods> listByCategory(Long categoryId, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Goods> list = goodsMapper.listByCategory(categoryId);
        PageInfo<Goods> pageInfo = new PageInfo<>(list);
        return PageInfoToPageDataConverter.convert(pageInfo);
    }
}
